package com.bdqn.controller;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bdqn.entity.PsLineInfo;
import com.bdqn.service.IPsLineInfoService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lcb
 * @since 2020-05-22
 */
@RestController
public class PsLineInfoController {
	@Autowired
	IPsLineInfoService Ipli;
	//获取全部线路信息
	@RequestMapping("line")
	public List<PsLineInfo> line() {
		return Ipli.selectAll();
	}
	//获取单个线路信息
	@RequestMapping("getOneLine")
	public PsLineInfo getOneLine(@RequestParam(name="id",required=false)Integer id){
		return Ipli.searchById(id);
	}
	//删除线路
	@RequestMapping("delLine")
	public boolean delLine(@RequestParam(name="id",required=false)Integer id) {
		return Ipli.removeById(id);
	}
	//增加线路
	@RequestMapping("addLine")
	public boolean addLine(@RequestParam(name="linecode",required=false)String linecode,
			@RequestParam(name="linename",required=false)String linename,
			@RequestParam(name="linelength",required=false)Double linelength,
			@RequestParam(name="backlength",required=false)Double backlength,
			@RequestParam(name="productdate",required=false)LocalDate productdate,
			@RequestParam(name="voltagelevel",required=false)String voltagelevel,
			@RequestParam(name="startpole",required=false)Long startpole,
			@RequestParam(name="endpole",required=false)Long endpole,
			@RequestParam(name="towerbasenum",required=false)Long towerbasenum,
			@RequestParam(name="runningId",required=false)Long runningId,
			@RequestParam(name="common",required=false)String common,
			@RequestParam(name="isstart",required=false)Integer isstart) {
		PsLineInfo plin=new PsLineInfo();
		plin.setLinecode(linecode);
		plin.setLinename(linename);
		plin.setLinelength(linelength);
		plin.setBacklength(backlength);
		plin.setProductdate(productdate);
		plin.setVoltagelevel(voltagelevel);
		plin.setStartpole(startpole);
		plin.setEndpole(endpole);
		plin.setTowerbasenum(towerbasenum);
		plin.setRunningId(runningId);
		plin.setCommon(common);
		plin.setIsstart(isstart);
		plin.setLastupdatetime(LocalDateTime.now());
		plin.setMaintenancecompany("线路管理员");
		plin.setCreationtime(LocalDateTime.now());
		plin.setCreatedby("admin");
		return Ipli.save(plin);
	}
	//修改线路
	@RequestMapping("lineUpdate")
	public boolean lineUpdate(@RequestParam(name="id",required=false)Integer id,
			@RequestParam(name="linecode",required=false)String linecode,
			@RequestParam(name="linename",required=false)String linename,
			@RequestParam(name="linelength",required=false)Double linelength,
			@RequestParam(name="backlength",required=false)Double backlength,
			@RequestParam(name="productdate",required=false)LocalDate productdate,
			@RequestParam(name="voltagelevel",required=false)String voltagelevel,
			@RequestParam(name="startpole",required=false)Long startpole,
			@RequestParam(name="endpole",required=false)Long endpole,
			@RequestParam(name="towerbasenum",required=false)Long towerbasenum,
			@RequestParam(name="runningId",required=false)Long runningId,
			@RequestParam(name="common",required=false)String common,
			@RequestParam(name="isstart",required=false)Integer isstart
			) {
		PsLineInfo pli=Ipli.searchById(id);
		pli.setLinecode(linecode);
		pli.setLinename(linename);
		pli.setLinelength(linelength);
		pli.setBacklength(backlength);
		pli.setProductdate(productdate);
		pli.setVoltagelevel(voltagelevel);
		pli.setStartpole(startpole);
		pli.setEndpole(endpole);
		pli.setTowerbasenum(towerbasenum);
		pli.setRunningId(runningId);
		pli.setCommon(common);
		pli.setIsstart(isstart);
		pli.setLastupdatetime(LocalDateTime.now());
		return Ipli.updateById(pli);
	}
	//修改状态
	@RequestMapping("isstartUpdate")
	public boolean isstartUpdate(@RequestParam(name="id",required=false)Integer id,
			@RequestParam(name="isstart",required=false)Integer isstart
			) {
		PsLineInfo pli=Ipli.searchById(id);
		pli.setIsstart(isstart);
		return Ipli.updateById(pli);
	}
}

